﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Attach_Open : System.Web.UI.Page
{
    RegistrationData reg = new RegistrationData();
    Communication cs = new Communication();
    DataSet ds = null;
    public const string svgDataKey = "svgDataKey";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Silpath"] != null)
        {
            string MessageID =  Crypto.DecryptStringAES(Convert.ToString(Request.QueryString["Silpath"]));
            BindMessage(Convert.ToInt32(MessageID)); 
            Response.Redirect(Convert.ToString(Session[svgDataKey]));
        }
        Response.Redirect("~/MyAccount.aspx");
    }


    void BindMessage(int ID)
    {
        if (Session["User"] != null)
        {
            ds = new DataSet();
            reg = (RegistrationData)Session["User"];
            cs.UserID = reg.UserID;
            cs.MessageID = ID;
            ds = cs.Select_Messages();
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataRow dr = ds.Tables[0].Rows[0]; 
                        if (!string.IsNullOrEmpty(Convert.ToString(dr["SilPath"])))
                        {
                            Session[svgDataKey] = Convert.ToString(dr["SilPath"]);

                        } 
                    } 
                } 
            } 
        }
    }

}